<?php

/**
 * This is the model class for table "character".
 *
 * The followings are the available columns in table 'character':
 * @property integer $id
 * @property integer $userId
 * @property integer $gameId
 * @property integer $guildId
 * @property string $name
 * @property integer $raceId
 * @property integer $sexId
 * @property integer $classId
 * @property integer $raidChar
 * @property integer $rankId
 * @property integer $roleId
 * @property string $avatar
 * @property string $signature
 *
 * The followings are the available model relations:
 * @property Adjustments[] $adjustments
 * @property Raids[] $raids
 * @property User $user
 * @property Game $game
 * @property Guild $guild
 * @property Race $race
 * @property Sex $sex
 * @property Class $class
 * @property Rank $rank
 * @property Role $role
 * @property Dkpchar $dkpchar
 * @property Galleryitems[] $galleryitems
 * @property Group[] $groups
 * @property Guild[] $guilds
 * @property Loot[] $loots
 * @property Personalmessages[] $personalmessages
 * @property Pointtriggers[] $pointtriggers
 * @property Post[] $posts
 * @property Topic[] $topics
 */
class Character extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Character the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'character';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('userId, gameId, guildId, raceId, sexId, classId, raidChar, rankId, roleId', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>105),
			array('avatar', 'length', 'max'=>65),
			array('signature', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, userId, gameId, guildId, name, raceId, sexId, classId, raidChar, rankId, roleId, avatar, signature', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'adjustments' => array(self::HAS_MANY, 'Adjustments', 'updatedById'),
			'raids' => array(self::HAS_MANY, 'Raids', 'updatedById'),
			'user' => array(self::BELONGS_TO, 'User', 'userId'),
			'game' => array(self::BELONGS_TO, 'Game', 'gameId'),
			'guild' => array(self::BELONGS_TO, 'Guild', 'guildId'),
			'race' => array(self::BELONGS_TO, 'Race', 'raceId'),
			'sex' => array(self::BELONGS_TO, 'Sex', 'sexId'),
			'class' => array(self::BELONGS_TO, 'Class', 'classId'),
			'rank' => array(self::BELONGS_TO, 'Rank', 'rankId'),
			'role' => array(self::BELONGS_TO, 'Role', 'roleId'),
			'dkpchar' => array(self::HAS_ONE, 'Dkpchar', 'characterId'),
			'galleryitems' => array(self::HAS_MANY, 'Galleryitems', 'characterId'),
			'groups' => array(self::MANY_MANY, 'Group', 'groupuser(characterId, groupId)'),
			'guilds' => array(self::HAS_MANY, 'Guild', 'characterId'),
			'loots' => array(self::HAS_MANY, 'Loot', 'updatedById'),
			'personalmessages' => array(self::HAS_MANY, 'Personalmessages', 'toId'),
			'pointtriggers' => array(self::HAS_MANY, 'Pointtriggers', 'updatedById'),
			'posts' => array(self::HAS_MANY, 'Post', 'modifyedById'),
			'topics' => array(self::HAS_MANY, 'Topic', 'characterId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'userId' => 'User',
			'gameId' => 'Game',
			'guildId' => 'Guild',
			'name' => 'Name',
			'raceId' => 'Race',
			'sexId' => 'Sex',
			'classId' => 'Class',
			'raidChar' => 'Raid Char',
			'rankId' => 'Rank',
			'roleId' => 'Role',
			'avatar' => 'Avatar',
			'signature' => 'Signature',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('userId',$this->userId);
		$criteria->compare('gameId',$this->gameId);
		$criteria->compare('guildId',$this->guildId);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('raceId',$this->raceId);
		$criteria->compare('sexId',$this->sexId);
		$criteria->compare('classId',$this->classId);
		$criteria->compare('raidChar',$this->raidChar);
		$criteria->compare('rankId',$this->rankId);
		$criteria->compare('roleId',$this->roleId);
		$criteria->compare('avatar',$this->avatar,true);
		$criteria->compare('signature',$this->signature,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}